<template>
  <div>
    <div class="warn-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        一键报警管理
      </h4>
      <!--         :rules="rules" -->
      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="140px"
        id="elform"
      >
        <el-form-item
          label="警情来源："
          prop="type"
          style="width: 450px; float: left"
        >
          <el-select
            v-model="formData.type"
            placeholder="请选择警情来源"
            clearable
            :style="{ width: '300px' }"
            style="float: left"
          >
            <el-option
              v-for="item in type"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="报警人姓名："
          prop="user_name"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.user_name"
            placeholder="请输入报警人姓名"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="处理状态："
          prop="status"
          style="width: 450px; float: left"
        >
          <el-select
            v-model="formData.status"
            placeholder="请选择处理状态"
            clearable
            :style="{ width: '300px' }"
            style="float: left"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.text"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="报警时段："
          prop="time"
          style="width: 450px; float: left"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '300px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="medium" style="float: float">
          <el-button
            @click="resetForm()"
            size="medium"
            style="
              background-color: #e6effa;
              color: #126bff;
              margin-left: 10px;
              height: 36px;
              width: 78px;
              border-radius: 6px;
              opacity: 1;
              font-size: 14px;
              font-family: Microsoft YaHei-Regular, Microsoft YaHei;
              font-weight: 400;
              float: left;
              border: none;
            "
            >重置</el-button
          >
          <el-button
            type="primary"
            size="medium"
            @click="submitForm(formData)"
            style="
              height: 36px;
              float: left;
              width: 78px;

              background-color: #126bff;
              border-radius: 6px;
              opacity: 1;
              color: #ffffff;
              font-size: 14px;
              font-family: Microsoft YaHei-Regular, Microsoft YaHei;
              font-weight: 400;
              margin-left: 10px;
            "
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- :span-method="objectSpanMethod" -->
    <div class="warn-content" style="width: 100%">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="school_name" label="学校名称"> </el-table-column> -->
        <el-table-column prop="type" label="警情来源">
          <template slot-scope="scope">
            <span v-if="scope.row.type == 1">小程序</span>
            <span v-else>主机</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="department_name" label="所属派出所">
        </el-table-column> -->
        <el-table-column prop="user_name" label="报警人姓名"> </el-table-column>
        <el-table-column prop="user_lxdh" label="报警人手机号">
          <template slot-scope="scope">
            <!-- <span v-if="scope.row.showIdCard">{{ scope.row.user_lxdh }}</span> -->
            <span>{{ scope.row.user_lxdh }}</span>
            <!-- <el-button
              type="text"
              icon="el-icon-view"
              @click="show(scope.row)"
            ></el-button> -->
          </template>
        </el-table-column>
        <!-- <el-table-column prop="sbmc" label="设备名称"> </el-table-column> -->
        <el-table-column prop="clr_name" label="处理人姓名" v-if="false">
        </el-table-column>
        <el-table-column prop="cl_time" label="处理时间" v-if="false">
        </el-table-column>
        <el-table-column prop="status" label="处理状态">
          <template v-slot="scope">
            <!-- <el-tag size="medium">{{ scope.row.name }}</el-tag> -->
            <el-tag
              size="medium"
              v-if="scope.row.status == 2"
              style="
                width: 50px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                color: #1cdc7c;
                border: 1px solid #1cdc7c;
                padding: 0;
                line-height: 30px;
              "
              >已处理</el-tag
            >
            <!--  -->
            <el-tag
              size="medium"
              v-if="scope.row.status == 1"
              style="
                width: 50px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                border: 1px solid #ff4444;
                color: #ff4444;
                padding: 0;
                line-height: 30px;
              "
              >未处理</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="address" label="报警位置"> </el-table-column>
        <el-table-column prop="create_time" label="报警时间">
          <template slot-scope="scope">
            {{ scope.row.create_time }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="scope.row.status == 1"
              @click="cl(scope.row)"
              >下发警情</el-button
            >
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; flex-direction: row-reverse">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[20, 50, 100]"
          :page-size="pageSize"
          layout="total, prev, pager, next, sizes"
          :total="total"
          style="float: right"
        >
        </el-pagination>
      </div>
    </div>
    <div>
      <detailDialog
        :dialogVsible="Visible"
        :detail="detaile"
        :detailvisible="detailvisible"
        @handel="handel"
        @Confirm="Confirm"
      ></detailDialog>
    </div>
    <div></div>
  </div>
</template>
<script>
import detailDialog from "@/components/detailDetail";
import { Loading } from "element-ui";
import { clickAlarmList } from "@/api/school/warn";
export default {
  name: "WARN",
  components: { detailDialog },
  data() {
    return {
      checkList: [],
      total: null,
      Visible: false,
      detailvisible: false,
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      optionsOne: [],
      emitPath: false,
      // pages: {
      // 按页数查询数据
      currentPage: 1,
      pageSize: 20,
      // },
      formData: {
        page: 1,
        pagesize: 20,
        // department_id: "",
        type: "",
        // school_name: "",
        user_name: "",
        status: "",
        time: "",
        ywlsh: JSON.parse(localStorage.getItem("userInfo")).user.ywlsh,
        // ywlsh: 1,
      },
      form: {
        name: "",
      },
      searchData: {
        page: 1,
        pagesize: 20,
        // department_id: "",
        type: "",
        // school_name: "",
        user_name: "",
        status: "",
        end_time: "",
        begin_time: "",
        ywlsh: JSON.parse(localStorage.getItem("userInfo")).user.ywlsh,
        // ywlsh: 1,
      },
      detaile: {},
      tableData: [],

      type: [
        {
          text: "报警主机",
          value: "2",
        },
        {
          text: "小程序",
          value: "1",
        },
      ],
      status: [
        {
          text: "已处理",
          value: "2",
        },
        {
          text: "未处理",
          value: "1",
        },
      ],
      datalist: [],
      detail: {},
    };
  },
  mounted() {
    this.initClickAlarmList();
    console.log(JSON.parse(localStorage.getItem("userInfo")).user.ywlsh);
  },
  computed: {},
  methods: {
    // objectSpanMethod({ row, column, rowIndex, columnIndex }) {
    //   console.log(row, column, rowIndex, columnIndex);

    //   if (row.user_name === "宁紫伟") {
    //     if (rowIndex % 2 === 0) {
    //       if (columnIndex % 2 === 0) {
    //         return {
    //           rowspan: 1,
    //           colspan: 2,
    //         };
    //       } else {
    //         return {
    //           rowspan: 0,
    //           colspan: 0,
    //         };
    //       }
    //     }
    //   }
    // },
    // 初始化警情列表
    initClickAlarmList() {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      // clickAlarmList()
      clickAlarmList(this.searchData).then((res) => {
        // console.log(res);
        if (res.code == 200) {
          loadingInstance.close();
          res.data.res.forEach((item, index) => {
            item.showIdCard = false;
          });
          that.total = res.data.count;
          that.tableData = res.data.res;
        } else {
          this.$message({
            message: res.message,
            type: "warning",
            duration: "2000",
          });
        }
      });
    },
    handel(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.detailvisible = e;
    },
    Confirm(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.detailvisible = e;
    },
    submitForm(formData) {
      let that = this;
      that.tableData = [];
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      this.searchData.user_name = formData.user_name; // 上报人姓名
      // this.searchData.school_name = formData.school_name; // 学校名称
      // this.searchData.department_id = formData.department_id; // 所属派出所
      this.searchData.type = formData.type; // 警情来源
      this.searchData.status = formData.status; // 警情来源
      this.searchData.page = 1;
      if (formData.time == [] || formData.time == null) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = formData.time[1];
        this.searchData.begin_time = formData.time[0];
      }
      console.log(this.searchData);
      clickAlarmList(this.searchData).then((res) => {
        loadingInstance.close();
        console.log(res);
        if (res.code == 200) {
          that.currentPage = 1;
          res.data.res.forEach((item, index) => {
            item.showIdCard = false;
            that.tableData = res.data.res;
          });
          that.total = res.data.count;
        } else {
          this.$message({
            message: res.message,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
      this.searchData = {
        page: 1,
        pagesize: 20,
        // department_id: "",
        type: "",
        // school_name: "",
        user_name: "",
        status: "",
        end_time: "",
        begin_time: "",
        ywlsh: JSON.parse(localStorage.getItem("userInfo")).user.ywlsh,
      };
      this.pageSize = 20;
      this.currentPage = 1;
      this.initClickAlarmList();
    },
    handleClick(row) {
      console.log(row);
      this.Visible = !this.Visible;
      this.detailvisible = !this.detailvisible;
      this.detaile = row;
      // this.detaile = row;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.searchData.pagesize = val;
      this.searchData.page = 1;
      this.currentPage = 1;
      this.initClickAlarmList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.searchData.page = val;
      this.initClickAlarmList();
    },
  },

  created() {},
};
</script>
<style scoped lang="scss">
#elform {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  /deep/.el-form-item__content {
    margin-left: 30px !important;
  }
}
.xxts h1 {
  font-size: 24px;
  font-weight: 400;
  color: #13213b;

  .el-checkbox {
    line-height: 20px;
  }
}
.xxts p {
  font-size: 19px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #111e36;
  line-height: 50px;
}
.xxts div .el-checkbox {
  height: 40px;
  line-height: 40px;
  font-size: 19px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #111e36;
  line-height: 25px;
}
.warn-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.warn-top {
  width: calc(100%);
}
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
.warn-content {
  margin-top: 20px;
  // border: 1px red solid;
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}
// /deep/ .has-gutter .thead {
//   border: 1px red solid !important;
// }
// /deep/.el-table .thead {
//   border: 1px red solid !important;
// }
.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }

/deep/ .el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  margin-top: 0;
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
}
/deep/.el-input--medium .el-input__inner {
  position: relative !important;
}
/deep/ .el-dialog__header {
  text-align: left;
  font-weight: 600;
  display: none !important;
}
.dialogTitle {
  display: flex;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: center;
  align-items: center;
  margin-bottom: 15px;
  img {
    width: 23px;
    height: 22px;
    margin-right: 10px;
  }
  h3 {
    font-size: 24px;
    font-weight: 400;
    color: #ff2d2d;
    line-height: 13px;
  }
}
/deep/.el-dialog__footer {
  // border: 1px red solid;
  padding: 10px 20px 20px;
  text-align: center;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
/deep/.el-dialog__footer button:nth-of-type(1) {
  width: 95px;
  height: 40px;
  background: #eef5ff;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  font-size: 18px;
  font-family: Microsoft YaHei-Regular, Microsoft YaHei;
  font-weight: 400;
  color: #126bff;
}
/deep/.el-dialog__footer button:nth-of-type(2) {
  width: 95px;
  height: 40px;
  background: #126bff;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  font-size: 17px;
  font-family: Microsoft YaHei-Regular, Microsoft YaHei;
  font-weight: 400;
  color: #ffffff;
}
.warningPass {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: flex-start;
  p {
    height: 40px;
    line-height: 40px;
    font-size: 19px;
    color: #111e36;
  }
}
.upIpfo {
  display: flex;
  width: 100%;
  //
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  //
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-textarea__inner {
  background-color: #eef5ff !important;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}
</style>
